package com.ms.dsq_english.wall

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.ms.dsq_english.R
import com.ms.dsq_english.adapter.RVAdapterAreaCurrentTo
import com.ms.dsq_english.http.HttpManager
import com.ms.dsq_english.model.AreaBean
import com.ms.dsq_english.model.AreaBean.DataBean.DistrictDataBean
import com.ms.dsq_english.utils.LogUtils
import com.ms.dsq_english.utils.MapUtilsParamNull
import com.ms.dsq_english.utils.ResultCheckUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.frag_area.*
import lecho.lib.hellocharts.model.*
import java.util.*
import kotlin.collections.ArrayList

/**
 * @Description:
 * @Author: zheng
 */
class AreaFragment : Fragment() {


    private lateinit var mContext: Context
    private val list: MutableList<AreaBean.DataBean.SalesRegionBean> = ArrayList()
    private val listt:ArrayList<AreaBean.DataBean.MonthBean> = ArrayList()
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
    {
        mContext = context!!

        return inflater.inflate(R.layout.frag_area, container, false)
    }


    override fun onResume() {
        super.onResume()
        Glide.with(mContext).load(R.drawable.img_area).into(area_img)
        area()
    }


    fun refresh() {
        area()
    }



    @SuppressLint("CheckResult")
    private fun area()
    {
            val params: HashMap<String, String> = MapUtilsParamNull()
                    .getBaseMap(mContext)

            HttpManager.getRetrofitInterface()
                    .getArea(params)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({ result: AreaBean ->
                        if (result.code == 10000) {
                            //图表
                            listt.clear()
                            listt.addAll(result.data.month_chart)

                            val shopData = result.data.month_chart
                            initComboLineColumnChartView(shopData)


                            //地图
                            list.clear()
                            list.addAll(result.data.sales_region)

                            yellow.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "山东省") {
                                        sales_num.text = "山东省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            green.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "河南省") {
                                        sales_num.text = "河南省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            bule.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "安徽省") {
                                        sales_num.text = "安徽省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            zi.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "江苏省") {
                                        sales_num.text = "江苏省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            gans.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "甘肃省") {
                                        sales_num.text = "甘肃省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            shanx.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "陕西省") {
                                        sales_num.text = "陕西省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sanx.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "山西省") {
                                        sales_num.text = "山西省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            ningx.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "宁夏回族自治区") {
                                        sales_num.text = "宁夏回族自治区门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            guangd.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "广东省") {
                                        sales_num.text = "广东省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng1.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "江西省") {
                                        sales_num.text = "江西省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng2.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "浙江省") {
                                        sales_num.text = "浙江省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng3.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "福建省") {
                                        sales_num.text = "福建省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng4.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "湖北省") {
                                        sales_num.text = "湖北省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng5.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "四川省") {
                                        sales_num.text = "四川省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng6.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "贵州省") {
                                        sales_num.text = "贵州省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng7.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "湖南省") {
                                        sales_num.text = "湖南省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng8.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "海南省") {
                                        sales_num.text = "海南省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng10.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "重庆") {
                                        sales_num.text = "重庆门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng11.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "天津") {
                                        sales_num.text = "天津门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng12.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "内蒙古自治区") {
                                        sales_num.text = "内蒙古自治区门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng13.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "黑龙江省") {
                                        sales_num.text = "黑龙江省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng14.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "吉林省") {
                                        sales_num.text = "吉林省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng15.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "辽宁省") {
                                        sales_num.text = "辽宁省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            sheng16.setOnClickListener {
                                var i = 0
                                while (i < list.size) {
                                    if (list[i].pname == "河北省") {
                                        sales_num.text = "河北省门店数："
                                        sales_num1.text = list[i].nums
                                    }
                                    i++
                                }
                            }
                            //县乡镇覆盖情况
                            initRecyclerViewCurrent(result.data.district_data)
                            area_time.text = "截止时间：" + result.data.last_time
                            area_xx1.text = result.data.month_district_data.month_district
                            area_xx2.text = result.data.month_district_data.month_shop_count
                            area_xx3.text = result.data.month_district_data.month_district_unit
                            area_xx4!!.text = result.data.month_district_data.month_shop_unit
                            area_c1.progress = result.data.month_district_data.month_active_district_rate.toInt()
                            area_c1.runProgressAnim(1000)
                            area_c2.progress = result.data.month_district_data.month_active_shop_rate.toInt()
                            area_c2.runProgressAnim(1000)


                            //上月
                            if (result.data.pre_order.size==0){
                                area_y1.text = ""
                                area_y2.text = ""
                                area_y3.text = ""
                                area_yy1.text = ""
                                area_yy2.text = ""
                                area_yy3.text = ""
                                area_yyy1.text = ""
                                area_yyy2.text = ""
                                area_yyy3.text = ""
                                area_yyyy1.text = ""
                                area_yyyy2.text = ""
                                area_yyyy3.text = ""
                                area_yyyyy1.text = ""
                                area_yyyyy2.text = ""
                                area_yyyyy3.text = ""
                            }
                            if (result.data.pre_order.size==1){
                                area_y1.text = result.data.pre_order[0].address
                                area_y2.text = result.data.pre_order[0].amount + "千元"
                                area_y3.text = result.data.pre_order[0].rate + "%"
                                area_yy1.text = ""
                                area_yy2.text = ""
                                area_yy3.text = ""
                                area_yyy1.text = ""
                                area_yyy2.text = ""
                                area_yyy3.text = ""
                                area_yyyy1.text = ""
                                area_yyyy2.text = ""
                                area_yyyy3.text = ""
                                area_yyyyy1.text = ""
                                area_yyyyy2.text = ""
                                area_yyyyy3.text = ""
                            }
                            if (result.data.pre_order.size==2){
                                area_y1.text = result.data.pre_order[0].address
                                area_y2.text = result.data.pre_order[0].amount + "千元"
                                area_y3.text = result.data.pre_order[0].rate + "%"
                                area_yy1.text = result.data.pre_order[1].address
                                area_yy2.text = result.data.pre_order[1].amount + "千元"
                                area_yy3.text = result.data.pre_order[1].rate + "%"
                                area_yyy1.text = ""
                                area_yyy2.text = ""
                                area_yyy3.text = ""
                                area_yyyy1.text = ""
                                area_yyyy2.text = ""
                                area_yyyy3.text = ""
                                area_yyyyy1.text = ""
                                area_yyyyy2.text = ""
                                area_yyyyy3.text = ""
                            }
                            if (result.data.pre_order.size==3){
                                area_y1.text = result.data.pre_order[0].address
                                area_y2.text = result.data.pre_order[0].amount + "千元"
                                area_y3.text = result.data.pre_order[0].rate + "%"
                                area_yy1.text = result.data.pre_order[1].address
                                area_yy2.text = result.data.pre_order[1].amount + "千元"
                                area_yy3.text = result.data.pre_order[1].rate + "%"
                                area_yyy1.text = result.data.pre_order[2].address
                                area_yyy2.text = result.data.pre_order[2].amount + "千元"
                                area_yyy3.text = result.data.pre_order[2].rate + "%"
                                area_yyyy1.text = ""
                                area_yyyy2.text = ""
                                area_yyyy3.text = ""
                                area_yyyyy1.text = ""
                                area_yyyyy2.text = ""
                                area_yyyyy3.text = ""
                            }
                            if (result.data.pre_order.size==4){
                                area_y1.text = result.data.pre_order[0].address
                                area_y2.text = result.data.pre_order[0].amount + "千元"
                                area_y3.text = result.data.pre_order[0].rate + "%"
                                area_yy1.text = result.data.pre_order[1].address
                                area_yy2.text = result.data.pre_order[1].amount + "千元"
                                area_yy3.text = result.data.pre_order[1].rate + "%"
                                area_yyy1.text = result.data.pre_order[2].address
                                area_yyy2.text = result.data.pre_order[2].amount + "千元"
                                area_yyy3.text = result.data.pre_order[2].rate + "%"
                                area_yyyy1.text = result.data.pre_order[3].address
                                area_yyyy2.text = result.data.pre_order[3].amount + "千元"
                                area_yyyy3.text = result.data.pre_order[3].rate + "%"
                                area_yyyyy1.text = ""
                                area_yyyyy2.text = ""
                                area_yyyyy3.text = ""
                            }
                            if (result.data.pre_order.size==5){
                                area_y1.text = result.data.pre_order[0].address
                                area_y2.text = result.data.pre_order[0].amount + "千元"
                                area_y3.text = result.data.pre_order[0].rate + "%"
                                area_yy1.text = result.data.pre_order[1].address
                                area_yy2.text = result.data.pre_order[1].amount + "千元"
                                area_yy3.text = result.data.pre_order[1].rate + "%"
                                area_yyy1.text = result.data.pre_order[2].address
                                area_yyy2.text = result.data.pre_order[2].amount + "千元"
                                area_yyy3.text = result.data.pre_order[2].rate + "%"
                                area_yyyy1.text = result.data.pre_order[3].address
                                area_yyyy2.text = result.data.pre_order[3].amount + "千元"
                                area_yyyy3.text = result.data.pre_order[3].rate + "%"
                                area_yyyyy1.text = result.data.pre_order[4].address
                                area_yyyyy2.text = result.data.pre_order[4].amount + "千元"
                                area_yyyyy3.text = result.data.pre_order[4].rate + "%"
                            }
                            if (result.data.now_order.size==0){
                                area_by1.text = ""
                                area_by2.text = ""
                                area_by3.text = ""
                                area_byy1.text = ""
                                area_byy2.text = ""
                                area_byy3.text = ""
                                area_byyy1.text = ""
                                area_byyy2.text = ""
                                area_byyy3.text = ""
                                area_byyyy1.text = ""
                                area_byyyy2.text = ""
                                area_byyyy3.text = ""
                                area_byyyyy1.text = ""
                                area_byyyyy2.text = ""
                                area_byyyyy3.text = ""
                            }
                            if (result.data.now_order.size==1){
                                area_by1.text = result.data.now_order[0].address
                                area_by2.text = result.data.now_order[0].amount + "千元"
                                area_by3.text = result.data.now_order[0].rate + "%"
                                area_byy1.text = ""
                                area_byy2.text = ""
                                area_byy3.text = ""
                                area_byyy1.text = ""
                                area_byyy2.text = ""
                                area_byyy3.text = ""
                                area_byyyy1.text = ""
                                area_byyyy2.text = ""
                                area_byyyy3.text = ""
                                area_byyyyy1.text = ""
                                area_byyyyy2.text = ""
                                area_byyyyy3.text = ""
                            }
                            if (result.data.now_order.size==2){
                                area_by1.text = result.data.now_order[0].address
                                area_by2.text = result.data.now_order[0].amount + "千元"
                                area_by3.text = result.data.now_order[0].rate + "%"
                                area_byy1.text = result.data.now_order[1].address
                                area_byy2.text = result.data.now_order[1].amount + "千元"
                                area_byy3.text = result.data.now_order[1].rate + "%"
                                area_byyy1.text = ""
                                area_byyy2.text = ""
                                area_byyy3.text = ""
                                area_byyyy1.text = ""
                                area_byyyy2.text = ""
                                area_byyyy3.text = ""
                                area_byyyyy1.text = ""
                                area_byyyyy2.text = ""
                                area_byyyyy3.text = ""
                            }
                            if (result.data.now_order.size==3){
                                area_by1.text = result.data.now_order[0].address
                                area_by2.text = result.data.now_order[0].amount + "千元"
                                area_by3.text = result.data.now_order[0].rate + "%"
                                area_byy1.text = result.data.now_order[1].address
                                area_byy2.text = result.data.now_order[1].amount + "千元"
                                area_byy3.text = result.data.now_order[1].rate + "%"
                                area_byyy1.text = result.data.now_order[2].address
                                area_byyy2.text = result.data.now_order[2].amount + "千元"
                                area_byyy3.text = result.data.now_order[2].rate + "%"
                                area_byyyy1.text = ""
                                area_byyyy2.text = ""
                                area_byyyy3.text = ""
                                area_byyyyy1.text = ""
                                area_byyyyy2.text = ""
                                area_byyyyy3.text = ""
                            }
                            if (result.data.now_order.size==4){
                                area_by1.text = result.data.now_order[0].address
                                area_by2.text = result.data.now_order[0].amount + "千元"
                                area_by3.text = result.data.now_order[0].rate + "%"
                                area_byy1.text = result.data.now_order[1].address
                                area_byy2.text = result.data.now_order[1].amount + "千元"
                                area_byy3.text = result.data.now_order[1].rate + "%"
                                area_byyy1.text = result.data.now_order[2].address
                                area_byyy2.text = result.data.now_order[2].amount + "千元"
                                area_byyy3.text = result.data.now_order[2].rate + "%"
                                area_byyyy1.text = result.data.now_order[3].address
                                area_byyyy2.text = result.data.now_order[3].amount + "千元"
                                area_byyyy3.text = result.data.now_order[3].rate + "%"
                                area_byyyyy1.text = ""
                                area_byyyyy2.text = ""
                                area_byyyyy3.text = ""
                            }
                            if (result.data.now_order.size==5) {
                                area_by1.text = result.data.now_order[0].address
                                area_by2.text = result.data.now_order[0].amount + "千元"
                                area_by3.text = result.data.now_order[0].rate + "%"
                                area_byy1.text = result.data.now_order[1].address
                                area_byy2.text = result.data.now_order[1].amount + "千元"
                                area_byy3.text = result.data.now_order[1].rate + "%"
                                area_byyy1.text = result.data.now_order[2].address
                                area_byyy2.text = result.data.now_order[2].amount + "千元"
                                area_byyy3.text = result.data.now_order[2].rate + "%"
                                area_byyyy1.text = result.data.now_order[3].address
                                area_byyyy2.text = result.data.now_order[3].amount + "千元"
                                area_byyyy3.text = result.data.now_order[3].rate + "%"
                                area_byyyyy1.text = result.data.now_order[4].address
                                area_byyyyy2.text = result.data.now_order[4].amount + "千元"
                                area_byyyyy3.text = result.data.now_order[4].rate + "%"
                            }
                        } else {
                            ResultCheckUtils().checkResult(mContext, result.code, result.msg)
                        }
                    }
                    ) { e: Throwable -> LogUtils.showLog(HttpManager.TAG, e.message) }
        }

    private fun initRecyclerViewCurrent(list: ArrayList<DistrictDataBean>) {
        area_rec.layoutManager = LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)
        area_rec.adapter = RVAdapterAreaCurrentTo(mContext, list)
        area_rec.start()
    }

    //X轴展示内容
    private fun getXValues(list: ArrayList<AreaBean.DataBean.MonthBean>): List<AxisValue>
    {

        val listAxisXValues = ArrayList<AxisValue>()

        listAxisXValues.add(AxisValue(0.toFloat()).setLabel(list[0].months ))
        listAxisXValues.add(AxisValue(1.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(2.toFloat()).setLabel(list[1].months ))
        listAxisXValues.add(AxisValue(3.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(4.toFloat()).setLabel(list[2].months ))
        listAxisXValues.add(AxisValue(5.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(6.toFloat()).setLabel(list[3].months ))
        listAxisXValues.add(AxisValue(7.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(8.toFloat()).setLabel(list[4].months ))
//        listAxisXValues.add(AxisValue(9.toFloat()).setLabel(""))

//
//        //设置X轴显示
//        for (i in list.indices)
//        {
//            if(i%2==0){
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(list[i].months ))
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(""))
//            }else{
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(list[i].months ))
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(""))
//            }
//        }


        return listAxisXValues
    }
    //Y轴展示内容
    private fun getYValues(maxYValue: Float, isHarPer: Boolean): List<AxisValue>
    {
        val listAxisYValues = ArrayList<AxisValue>()
        var per = 10

        when
        {
            maxYValue > 0 && maxYValue <= 50 -> per = 5
            maxYValue > 50 && maxYValue <= 100 -> per = 10
            maxYValue > 100 && maxYValue <= 500 -> per = 50
            maxYValue > 500 && maxYValue <= 1000 -> per = 100
            maxYValue > 1000 && maxYValue <= 5000 -> per = 250
            maxYValue > 5000 && maxYValue <= 10000 -> per = 500
            maxYValue > 10000 -> per = 1000
        }

        //设置Y轴显示
        var i = 0
        while (i <= maxYValue)
        {
            i += if (isHarPer)
            {
//                listAxisYValues.add(AxisValue(i.toFloat())
//                        .setLabel("${formatPer(i * 100 / maxYValue)}%"))
                listAxisYValues.add(AxisValue(i.toFloat()).setLabel(i.toString()))
                per
            }
            else
            {
                listAxisYValues.add(AxisValue(i.toFloat()).setLabel(i.toString()))

                per
            }
        }

        return listAxisYValues
    }
    private fun formatPer(per: Float): Int
    {
        return when
        {
            per > 0 && per <= 7 -> 5
            per > 7 && per <= 12 -> 10
            per > 12 && per <= 17 -> 15
            per > 17 && per <= 22 -> 20
            per > 22 && per <= 27 -> 25
            per > 27 && per <= 32 -> 30
            per > 32 && per <= 37 -> 35
            per > 37 && per <= 42 -> 40
            per > 42 && per <= 47 -> 45
            per > 47 && per <= 52 -> 50
            per > 52 && per <= 57 -> 55
            per > 57 && per <= 62 -> 60
            per > 62 && per <= 67 -> 65
            per > 67 && per <= 72 -> 70
            per > 72 && per <= 77 -> 75
            per > 77 && per <= 82 -> 80
            per > 82 && per <= 87 -> 85
            per > 87 && per <= 92 -> 90
            per > 92 && per <= 97 -> 95
            per > 97 && per <= 100 -> 100
            else -> 0
        }
    }

    //X轴
    private fun getXAxis(list: ArrayList<AreaBean.DataBean.MonthBean>): Axis
    {
        //X轴
        val axisX = Axis()
        //X轴标注
        //        axisX.setName("X轴");
        //设置字体颜色
        axisX.textColor = Color.parseColor("#748ebf")
        //设置字体大小
        axisX.textSize = 6
        //是否有分割线
        axisX.setHasLines(false)
        //X坐标轴字体是否斜体
        axisX.setHasTiltedLabels(false)
        //填充X轴的坐标名称
        axisX.values = getXValues(list)
        //设置轴标签和名字的字体
        //        axisX.setTypeface(Typeface typeface);
        //设置轴标签可显示的最大字符个数，范围在0-32之间
        //        axisX.setMaxLabelChars(5);
        //设置是否自动生成轴对象，自动适应表格的范围
        axisX.isAutoGenerated = false
        //设置是否将轴坐标的值显示在图表内侧
        axisX.isInside = false

        return axisX
    }
    //Y轴
    private fun getYAxis(maxYValue: Float, isHasPer: Boolean): Axis
    {
        //Y轴(不设置setValues会根据数据的大小自动设置Y轴上限)
        val axisY = Axis()
        //Y轴标注
        //        axisY.setName("Y轴");
        //设置字体颜色
        axisY.textColor = Color.parseColor("#748ebf")
        //设置字体大小
        axisY.textSize = 7
        //是否有分割线
        axisY.setHasLines(true)
        axisY.lineColor = Color.parseColor("#308EE3FF")
        //Y坐标轴字体是否斜体
        axisY.setHasTiltedLabels(false)
        //填充Y轴的坐标名称
        axisY.values = getYValues(maxYValue, isHasPer)
        //设置轴标签和名字的字体
        //        axisY.setTypeface(Typeface typeface);
        //设置轴标签可显示的最大字符个数，范围在0-32之间
        axisY.maxLabelChars = 10
        //设置是否自动生成轴对象，自动适应表格的范围
        axisY.isAutoGenerated = false
        //设置是否将轴坐标的值显示在图表内侧
        axisY.isInside = false

        return axisY
    }

    //添加柱

    private fun addColumn(data: AreaBean.DataBean.MonthBean,isShow: Boolean,order_num:String,active_num:String): Column
    {
        var order_nums = ""
        var active_nums = ""
        if (isShow){
            order_nums=order_num
            active_nums=active_num
        }
        val listColumnValue = ArrayList<SubcolumnValue>()


        listColumnValue.add(SubcolumnValue(data.retailers.toFloat(),
                if (isShow) Color.parseColor("#E5981F")else
                    Color.parseColor("#00000000"))
                .setLabel(active_nums))
        listColumnValue.add(SubcolumnValue(data.districts.toFloat(),
                if (isShow) Color.parseColor("#029BE8") else
                    Color.parseColor("#00000000"))
                .setLabel(order_nums))

        //柱
        val column = Column(listColumnValue)
        //柱的数据坐标是否加上备注
        column.setHasLabels(true)
        //点击数据坐标提示数据（设置column.setHasLabels(true);就无效）
//        column.setHasLabelsOnlyForSelected(true)
        return column
    }
    private fun initComboLineColumnChartView(list: ArrayList<AreaBean.DataBean.MonthBean>)
    {
        var maxYValue = 0f
        var cMaxYValue = 0f
        var lMaxYValue = 0f
        var setPer = 1f

        for (data in list)
        {
            if (data.retailers.toFloat() > cMaxYValue)
            {
                cMaxYValue = data.retailers.toFloat()
            }

            if (data.districts.toFloat() > cMaxYValue)
            {
                cMaxYValue = data.districts.toFloat()
            }

        }

        maxYValue = cMaxYValue
        setPer = cMaxYValue / lMaxYValue

        LogUtils.showLog("tables", "maxYValue=$maxYValue-cMaxYValue=$cMaxYValue-lMaxYValue=$lMaxYValue-setPer=$setPer")

        //设置线数据
        val listLine = ArrayList<Line>()
        listLine.add(addLine(list, setPer,"1"))
        listLine.add(addLine(list, setPer,"2"))

        val lineChartData = LineChartData()
        lineChartData.lines = listLine

        //设置柱状图数据
        val listColumn = ArrayList<Column>()
        for (i in list.indices)
        {
            if (i==list.size-1){
                listColumn.add(addColumn(list[i],true,"",""))
                listColumn.add(addColumn(list[i],false,listt.get(i).districts,""))
            }else{
                listColumn.add(addColumn(list[i],true,"",""))
                listColumn.add(addColumn(list[i],false,"",""))
            }


        }

        val columnChartData = ColumnChartData()
        columnChartData.columns = listColumn

        ////////////////
        //给图表设置数据
        val comboLineColumnChartData = ComboLineColumnChartData()
        comboLineColumnChartData.lineChartData = lineChartData
        comboLineColumnChartData.columnChartData = columnChartData

        //设置标签背景颜色
        comboLineColumnChartData.valueLabelBackgroundColor = resources.getColor(R.color.transparent)
        //设置是否自动绘制标签背景
        comboLineColumnChartData.isValueLabelBackgroundAuto = false
        //设置标签文字颜色，默认为白色
        comboLineColumnChartData.setValueLabelsTextColor(Color.parseColor("#748ebf"))
        //设置标签文字字号，默认为12sp
        comboLineColumnChartData.valueLabelTextSize = 6

        //X轴在底部
        comboLineColumnChartData.axisXBottom = getXAxis(list)
        //Y轴设置在左边
        comboLineColumnChartData.axisYLeft = getYAxis(maxYValue, false)
        //Y轴设置在右边
        comboLineColumnChartData.axisYRight = getYAxis(maxYValue, true)
        frg_trs_ccv_clccv_tra.comboLineColumnChartData = comboLineColumnChartData

        //设置图表是可以交互的（拖拽，缩放等效果的前提）
        frg_trs_ccv_clccv_tra.isInteractive = false

        when
        {
            maxYValue > 0 && maxYValue <= 25 -> maxYValue += 5
            maxYValue > 25 && maxYValue <= 50 -> maxYValue += 10
            maxYValue > 50 && maxYValue <= 100 -> maxYValue += 20
            maxYValue > 100 && maxYValue <= 250 -> maxYValue += 50
            maxYValue > 250 && maxYValue <= 500 -> maxYValue += 100
            maxYValue > 500 && maxYValue <= 1000 -> maxYValue += 200
            maxYValue > 1000 && maxYValue <= 5000 -> maxYValue += 1000
            maxYValue > 5000 && maxYValue <= 10000 -> maxYValue += 2000
            maxYValue > 10000 -> maxYValue += 3000
        }

        //设置坐标轴的范围(left-1,right+1可以使X轴坐标前后有空间)
        val viewport = Viewport(-1f, maxYValue, getXValues(list).size.toFloat(), 0f)

        frg_trs_ccv_clccv_tra.maximumViewport = viewport
        frg_trs_ccv_clccv_tra.currentViewport = viewport
    }

    //添加线
    private fun addLine(list: java.util.ArrayList<AreaBean.DataBean.MonthBean>, linePer: Float, line: String): Line
    {
        var colorLine = ""
        val listPointValue = java.util.ArrayList<PointValue>()

//        //设置图表数据点显示
//        for (i in list.indices)
//        {
//            listPointValue.add(PointValue(i.toFloat(), list[i].active_rate.toInt() * linePer)
//                    .setLabel(""))
////                    .setLabel("${list[i].active_rate.toInt()}%"))
//        }
        if (line.equals("1")){
            listPointValue.add(PointValue(0.toFloat(), list[0].retailers.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(2.toFloat(), list[1].retailers.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(4.toFloat(), list[2].retailers.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(6.toFloat(), list[3].retailers.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(8.toFloat(), list[4].retailers.toInt() * 1f)
                    .setLabel(""))

            colorLine ="#E5981F"
        }else if (line.equals("2")){
            listPointValue.add(PointValue(0.toFloat(), list[0].districts.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(2.toFloat(), list[1].districts.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(4.toFloat(), list[2].districts.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(6.toFloat(), list[3].districts.toInt() * 1f)
                    .setLabel(""))
            listPointValue.add(PointValue(8.toFloat(), list[4].districts.toInt() * 1f)
                    .setLabel(""))

            colorLine ="#029BE8"
        }

        //折线
        val line = Line(listPointValue)
        //是否用线显示 如果为false 则没有曲线只有点显示
        line.setHasLines(true)
        //折线颜色
        line.color = Color.parseColor(colorLine)
        //折线粗细
        line.strokeWidth = 1
        //是否有数据点
        line.setHasPoints(true)
        //数据点大小
        line.pointRadius = 1
        //数据点颜色
        line.pointColor = Color.parseColor(colorLine)
        //折线上每个数据点形状(CIRCLE SQUARE DIAMOND)
        line.shape = ValueShape.CIRCLE
        //是否平滑
        line.isCubic = true
        //是否填充曲线的面积
        line.isFilled = false
        //曲线的数据坐标是否加上备注
        line.setHasLabels(true)
        //点击数据坐标提示数据（设置line.setHasLabels(true);就无效）
        //      line.setHasLabelsOnlyForSelected(true);

        return line
    }
}